#include "Pacs_ShowPicWidget.h"
#include <QLabel>
#include <QVBoxLayout>
#include <QMessageBox>
#include <qDebug>
#include <QPushButton>
#include <QMouseEvent>
#include "PacsClient.h"


Pacs_ShowPicWidget::Pacs_ShowPicWidget(QWidget *parent)
	: QWidget(parent)
{
	//QPushButton *mm = new QPushButton;
	ui.setupUi(this);
	m_nIndex = -1;
	newLabel  = new QLabel;
	newLabel->setFixedSize(QSize(50,50));
	QVBoxLayout *buttonLayout = new QVBoxLayout;
	buttonLayout->addWidget(newLabel);
	buttonLayout->setAlignment(Qt::AlignRight | Qt::AlignTop);
	newLabel->setStyleSheet("border-image:url(\":/Pacs_Client/image/select.png\")");
	ui.picLabel->setLayout(buttonLayout);
	newLabel->hide();
}

void Pacs_ShowPicWidget::setLabelName(const QString name)
{
	ui.label->setText(name);
}
void Pacs_ShowPicWidget::setBackgroundImg(const QImage& image)
{
	QPixmap tempPixmap = QPixmap::fromImage(image);
	//ui.pic_btn->setIcon(QIcon(tempPixmap));
	//ui.pic_btn->setIconSize(QSize(ui.pic_btn->width(), ui.pic_btn->height()));
	QPixmap tempPixmap1 = tempPixmap.scaled(ui.picLabel->size());
	ui.picLabel->setPixmap(tempPixmap1);
	m_showPicView = new Pacs_ShowPicView;
	m_showPicView->setPic(tempPixmap);
	m_showPicView->hide();
}
void Pacs_ShowPicWidget::setPicIndex(int nIndex)
{
	m_nIndex = nIndex;
}

int Pacs_ShowPicWidget::getPicIndex()
{
	return m_nIndex;
}

void Pacs_ShowPicWidget::hideSelLabel()
{
	newLabel->hide();
}

const QString Pacs_ShowPicWidget::getLabelName()
{
	return ui.label->text();
}
void Pacs_ShowPicWidget::mousePressEvent(QMouseEvent *event)
{
	if (event->button() == Qt::LeftButton)
	{
		if (newLabel->isHidden())
		{
			PacsClient::getClientInstance()->GetCurrentPatient()->patientReport()->AddSelectImage(m_strImagePath);;
			newLabel->showNormal();
			emit(isSelect(true, m_nIndex));
		}
		else
		{
			PacsClient::getClientInstance()->GetCurrentPatient()->patientReport()->RemoveSelectImage(m_strImagePath);
			newLabel->hide();
			emit(isSelect(false, m_nIndex));
		}
	}
	QWidget::mousePressEvent(event);
}
// void Pacs_ShowPicWidget::on_pic_btn_clicked()
// {
// 	//QMessageBox::information(NULL, "Notice", this->objectName());
// 	QString objname = this->objectName();
// 	
// }

void Pacs_ShowPicWidget::enterEvent(QEvent *)
{
	qDebug() << "Mouse Enter";
	m_showPicView->showNormal();
}
void Pacs_ShowPicWidget::leaveEvent(QEvent *)
{
	qDebug() << "Mouse Leave";
	m_showPicView->hide();
}

void Pacs_ShowPicWidget::addLabelName(const QString strName)
{
	ui.label->setText(ui.label->text()+strName);
}

void Pacs_ShowPicWidget::SetImageFilePath(const QString& strFilePath)
{
	m_strImagePath = strFilePath;
}

QString Pacs_ShowPicWidget::imageFilePath() const
{
	return m_strImagePath;
}


Pacs_ShowPicWidget::~Pacs_ShowPicWidget()
{
	delete newLabel;
	delete m_showPicView;
}
